<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/assets/css/admin.css">
</head>
<body>
  <div class="login">
    <form class="login-wrap" id="myForm">
      <img class="avatar" src="/assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong> 用户名或密码错误！
      </div> -->
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" class="form-control" placeholder="邮箱" name="email" value="admin@baixiu.com" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" name="password" value="123456" class="form-control" placeholder="密码">
      </div>
      <!-- <a class="btn btn-primary btn-block" href="index.html">登 录</a> -->
      <input type="button" value="登录" id="btnLogin" class="btn btn-primary btn-block">
    </form>
  </div>
</body>
</html>
<!-- 引入jquery库文 -->
<script src="/assets/vendors/jquery/jquery.js"></script>
<script>
  //1.给按钮注册事件
  $("#btnLogin").on("click",function(){
    // alert("点击")
    //2.发送异步ajax请求
    $.ajax({
      //请求的数据信息
      type:"post",
      url:"/login",
      data: $("#myForm").serialize(), // 表单序列化获取form表单input标签带name属性的值
      dataType: "json",
      success: function(res){
        //判断响应结果
        if(res&&res.code==0){ // 登录成功
          location.href = "/" // 跳转到首页
        }
      }
    })
  })
</script>
